package www.woniuxy.com.class112.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import www.woniuxy.com.class112.entity.SpecialAgents;
import www.woniuxy.com.class112.form.userInfo.SelectAgentInfoPageForm;
import www.woniuxy.com.class112.form.userInfo.addAgentForm;
import www.woniuxy.com.class112.param.userInfo.SelectAgentInfoPageParam;
import www.woniuxy.com.class112.param.userInfo.addAgentParam;
import www.woniuxy.com.class112.service.AgentService;
import www.woniuxy.com.class112.util.Result;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/agent")
@Api(tags = "特派员相关接口")
public class AgentController {
    @Resource
    private AgentService agentService;
    @PostMapping("/addAgent")
    @ApiOperation("新增特派员")
    public Result addAgent(@RequestBody addAgentForm form)throws Exception{
        agentService.addAgent(BeanUtil.toBean(form, addAgentParam.class));
        return Result.success("新增成功特派员",null);
    }
    @PostMapping("/selectAgentInfo")
    @ApiOperation("搜索特派员")
    public Result selectAgentInfo(@RequestBody SelectAgentInfoPageForm form) throws Exception {
        PageInfo<SpecialAgents> specialAgentsPageInfo = agentService.selectAgentInfo(BeanUtil.toBean(form, SelectAgentInfoPageParam.class));
        return Result.success("搜索成功",specialAgentsPageInfo);
    }
    @GetMapping("/adminselectAgentInfo")
    @ApiOperation("管理员搜索特派员")
    public Result adminselectAgentInfo(String name) throws Exception {
        List<SpecialAgents> specialAgentsPageInfo = agentService.adminselectAgentInfo(name);
        return Result.success("搜索成功",specialAgentsPageInfo);
    }
}
